/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : WebUtil.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Dec 12, 2008       Raghu Sarraff			       Created
 */
package net.lwf.util.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Type the class description here
 *  
 */
public class WebUtil {
	
	public static void setRequestAttribute(HttpServletRequest request, String attribute, Object value) {
		request.setAttribute(attribute, value);
	}
	
	public static void setAttribute(HttpServletRequest request, String attribute, Object value) {
		//HttpSession session = request.getSession();
		HttpSession session = getSession(request);
		session.setAttribute(attribute, value);
	}
	
	public static Object getAttribute(HttpServletRequest request, String attribute) {
		//HttpSession session = request.getSession();
		HttpSession session = getSession(request);
		return session.getAttribute(attribute);
	}
	
	public static void removeAttribute(HttpServletRequest request, String attribute) {
		//HttpSession session = request.getSession();
		HttpSession session = getSession(request);
		Object obj = session.getAttribute(attribute);
		if(obj != null) {
			session.removeAttribute(attribute);
		}
	}
	
	public static String getMustParameter(HttpServletRequest request, String parameter) {
		String value = request.getParameter(parameter);
		if(value == null) {
			value = (String) getAttribute(request, parameter);
		}
		else {
			setAttribute(request, parameter, value);
		}
		return value;
	}
	
	public static HttpSession getSession(HttpServletRequest request) {
		return request.getSession();
	}

}

